<template>
  <div id="list">
    <ul style="padding-left: 0">
      <li
        v-for="(item, index) in admins"
        :key="index"
        :class="{
          active: currentSession
            ? item.username === currentSession.username
            : false
        }"
        v-on:click="changecurrentSession(item)"
      >
        <!--   :class="[item.id === currentSession ? 'active':'']" -->

        <el-avatar class="avatar" :src="item.userFace"></el-avatar>

        <p class="name">
          <el-badge
            :is-dot="isDot[user.username + '#' + item.username]"
            class="item"
            >{{ item.name }}</el-badge
          >
        </p>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "list",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user"))
    };
  },
  computed: mapState(["isDot", "admins", "currentSession"]),
  methods: {
    changecurrentSession(currentSession) {
      this.$store.commit("changecurrentSession", currentSession);
    }
  }
};
</script>

<style lang="scss" scoped>
#list {
  li {
    padding: 0 15px;
    border-bottom: 1px solid #292c33;
    cursor: pointer;
    &:hover {
      background-color: rgba(255, 255, 255, 0.03);
    }
  }
  li.active {
    /*注意这个是.不是冒号:*/
    background-color: rgba(255, 255, 255, 0.1);
  }
  .avatar {
    border-radius: 2px;
    width: 30px;
    height: 30px;
    vertical-align: middle;
  }
  .name {
    display: inline-block;
    margin-left: 15px;
  }
}
</style>
